package com.zhouyu.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.stereotype.Component;

/**
 * @ClassName:CustomeBean
 * @Auther: xierongchang
 * @Description:
 * @Date: 2024/6/20 16:03
 * @Version: v1.0.0
 */
@Component
public class CustomerBean implements BeanFactoryAware, BeanNameAware, InitializingBean, DisposableBean {

	private String name;

	private String address;

	private BeanFactory beanFactory;
	private String beanName;

	public CustomerBean() {
		System.out.println("第6步：【构造器】调用CustomBean的构造器实例化");
	}

	public void xml_init(){
		System.out.println("【init-method】调用<bean>的init-method属性指定的初始化方法");
	}

	public void xml_destroy(){
		System.out.println("销毁");
	}



	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		System.out.println("第10步：【执行BeanFactoryAware接口的setBeanFactory方法】setBeanName后调用");
		this.beanFactory = beanFactory;
	}

	@Override
	public void setBeanName(String name) {
		System.out.println("第9步：【执行BeanNameAware接口的setBeanName方法】属性注入后调用, 此时s = "+name);
		this.beanName= name;
	}

	@Override
	public void destroy() throws Exception {
		System.out.println("【执行DiposibleBean接口的destroy方法】在processAfterInitialization之后,配置的xml_destroy之前调用");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("【执行InitializingBean接口的afterPropertiesSet方法】在processBeforeInitialization之后,配置的xml_init之前调用");
	}


	public String getName() {
		return name;
	}

	public void setName(String name) {
		System.out.println("第7步：【注入属性】注入属性name");
		this.name = name;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		System.out.println("第8步：【注入属性】注入属性address");
		this.address = address;
	}
}
